use "kriner_goldfarb_science_communication_replication_data.dta", replace

* Demos *
gen white = 0
replace white = 1 if race == 1
gen education = educ
gen age = 2015-birthyr
gen male = 0
replace male = 1 if gender == 1
gen income = faminc 
replace income = . if faminc == 97

* Party *
gen dem3 = 0
replace dem3 = 1 if pid7 == 1
replace dem3 = 1 if pid7 == 2
gen dem5 = dem3
replace dem5 = 1 if pid7 == 3
gen gop3 = 0
replace gop3 = 1 if pid7 == 7
replace gop3 = 1 if pid7 == 6
gen gop5 = gop3
replace gop5 = 1 if pid7 == 5
gen ind5 = 0
replace ind5 = 1 if gop5 == 0 & dem5 == 0

* Ideology *
gen ideology = ideo5
recode ideology (6=.)
recode ideology (8=.)
gen ideology2 = ideo5
replace ideology2 = 3 if ideology2 == 6
recode ideology2 (8=.)

gen conservative = CC334A
replace conservative = . if CC334A == 98
replace conservative = . if CC334A == 8

gen conservative2 = CC334A
replace conservative2 = . if CC334A == 98
replace conservative2 = 4 if CC334A == 8

* Science Spending Estimate *
gen sciencespendguess = BOS313
recode sciencespendguess (-8=.)

gen ordsciencespendguess = .
replace ordsciencespendguess = 1 if sciencespendguess > 0 & sciencespendguess < 6
replace ordsciencespendguess = 2 if sciencespendguess > 5 & sciencespendguess < 11
replace ordsciencespendguess = 3 if sciencespendguess > 10 & sciencespendguess < 21
replace ordsciencespendguess = 4 if sciencespendguess > 20 & sciencespendguess < 101
replace ordsciencespendguess = 1 if sciencespendguess == 0

* Science Spending Preference *
gen sciencespendpref3 = BOS314
recode sciencespendpref3 (8=.)

gen increasess = sciencespendpref3
recode increasess (2=0) (3=0) (8=.)

* Correction treatment *
gen guesscorrected = 0
replace guesscorrected = 1 if BOS314_treat == 2

* Interactions *
gen guesscorrectedxgop5 = guesscorrected*gop5
gen guesscorrectedxdem5 = guesscorrected*dem5
gen guesscorrectedxsciencespendguess = sciencespendguess*guesscorrected
gen guesscorrectedxordspendguess = ordsciencespendguess*guesscorrected
gen guesscorrectedxconservative = guesscorrected*conservative
gen guesscorrectedxconservative2 = guesscorrected*conservative2

* Labels *
label var dem5 "Democrat"
label var gop5 "Republican"
label var dem3 "Democrat (no leaners)"
label var gop3 "Republican (no leaners)"
label var education "Education"
label var age "Age"
label var white "White"
label var male "Male"
label var ideology "Ideological Conservativism"
label var ideology2 "Ideological Conservativism"
label var conservative "Ideological Conservativism"
label var conservative2 "Ideological Conservativism"
label var guesscorrected "Estimate Corrected"
label var guesscorrectedxgop5 "Correction * Republican"
label var guesscorrectedxdem5 "Correction * Democrat"
label var guesscorrectedxsciencespendguess "Correction * Spending estimate"
label var guesscorrectedxconservative "Correction * Conservatism"
label var guesscorrectedxconservative2 "Correction * Conservatism"

label var sciencespendguess "Estimated % of budget allocated to science spending"

* Replicate Tables from Text *

* Table 1: Modeling Science Spending Estimates *
reg sciencespendguess gop5 dem5 conservative2 education white male age 
outreg2 using sstable1, word dec(2) label replace

* Table 2: Modeling Support for Increasing Science Spending *
logit increasess guesscorrected gop5 dem5 conservative2 education white male age 
outreg2 using sstable2, word dec(2) label replace
logit increasess guesscorrected guesscorrectedxgop5 guesscorrectedxdem5 gop5 dem5 conservative2 education white male age 
outreg2 using sstable2, word dec(2) label append
logit increasess guesscorrected guesscorrectedxconservative2 gop5 dem5 conservative2 education white male age 
outreg2 using sstable2, word dec(2) label append
logit increasess guesscorrected guesscorrectedxsciencespendguess gop5 dem5 conservative2 education white male age sciencespendguess
outreg2 using sstable2, word dec(2) label append sortvar(guesscorrected guesscorrectedxgop5 guesscorrectedxdem5 guesscorrectedxconservative2 guesscorrectedxsciencespendguess)

* Replicate Figures from Text *

* Figure 1: Graphical Plots of Science Spending Estimates *
graph box sciencespendguess,horizontal noout note("") graphregion(fcolor(white)) box(1, color(black)) 
label var sciencespendguess "Science spending guess"

* Figure 2: Effect Sizes from Simulations *

gen fig2mean = .
gen fig2upper = .
gen fig2lower = .
gen fig2label = _n
replace fig2label = . if fig2label > 9
label define fig2labels 1 "Correction" 2 "Republican" 3 "Democrat" 4 "Conservatism" 5 "Education" 6 "Non-white" 7 "Male" 8 "Age" 
label values fig2label fig2labels
label var fig2label ""

estsimp logit increasess guesscorrected gop5 dem5 conservative2 education white male age 
setx median 
setx dem5 0 gop5 0 male 0  white 1
setx guesscorrected 0
simqi, genpr(preds0 preds1)
_pctile preds1, p(2.5,97.5)
egen x = mean(preds1)
egen baseline = mean(preds1)
drop x preds0 preds1

setx guesscorrected 1
simqi, genpr(preds0 preds1)
_pctile preds1, p(2.5,97.5)
replace fig2upper = r(r1) if fig2label == 1
replace fig2lower = r(r2) if fig2label == 1 
egen x = mean(preds1)
replace fig2mean = x if fig2label == 1
drop x preds0 preds1

setx guesscorrected 0 gop5 1
simqi, genpr(preds0 preds1)
_pctile preds1, p(2.5,97.5)
replace fig2upper = r(r1) if fig2label == 2
replace fig2lower = r(r2) if fig2label == 2 
egen x = mean(preds1)
replace fig2mean = x if fig2label == 2
drop x preds0 preds1

setx gop5 0 dem5 1
simqi, genpr(preds0 preds1)
_pctile preds1, p(2.5,97.5)
replace fig2upper = r(r1) if fig2label == 3
replace fig2lower = r(r2) if fig2label == 3 
egen x = mean(preds1)
replace fig2mean = x if fig2label == 3
drop x preds0 preds1

setx dem5 0 conservative2 7
simqi, genpr(preds0 preds1)
_pctile preds1, p(2.5,97.5)
replace fig2upper = r(r1) if fig2label == 4
replace fig2lower = r(r2) if fig2label == 4 
egen x = mean(preds1)
replace fig2mean = x if fig2label == 4
drop x preds0 preds1

setx conservative2 median
setx education 6
simqi, genpr(preds0 preds1)
_pctile preds1, p(2.5,97.5)
replace fig2upper = r(r1) if fig2label == 5
replace fig2lower = r(r2) if fig2label == 5 
egen x = mean(preds1)
replace fig2mean = x if fig2label == 5
drop x preds0 preds1

setx education median
setx white 0
simqi, genpr(preds0 preds1)
_pctile preds1, p(2.5,97.5)
replace fig2upper = r(r1) if fig2label == 6
replace fig2lower = r(r2) if fig2label == 6 
egen x = mean(preds1)
replace fig2mean = x if fig2label == 6
drop x preds0 preds1

setx white 1 male 1
simqi, genpr(preds0 preds1)
_pctile preds1, p(2.5,97.5)
replace fig2upper = r(r1) if fig2label == 7
replace fig2lower = r(r2) if fig2label == 7 
egen x = mean(preds1)
replace fig2mean = x if fig2label == 7
drop x preds0 preds1

setx male 0 age 85
simqi, genpr(preds0 preds1)
_pctile preds1, p(2.5,97.5)
replace fig2upper = r(r1) if fig2label == 8
replace fig2lower = r(r2) if fig2label == 8 
egen x = mean(preds1)
replace fig2mean = x if fig2label == 8
drop x preds0 preds1

gen fig2meandiff = fig2mean-baseline
gen fig2lowerdiff = fig2lower-baseline
gen fig2upperdiff = fig2upper-baseline

eclplot fig2meandiff fig2lowerdiff fig2upperdiff fig2label, ylabel(-.2 -.1 0 .1 .2 .3) ytitle("Change in probability of supporting increase" " ") xtitle("") xlabel(1 2 3 4 5 6 7 8,angle(vertical)) yline(0) xscale(range(.75 8.25)) graphregion(fcolor(white))  ciopts(blcolor(black)) estopts(mcolor(black) msymbol(circle))

* Figure 3: Interaction Plot *

logit increasess i.guesscorrected##c.sciencespendguess gop5 dem5 conservative2 education white male age 
margins, at(sciencespendguess=(0(1)50) guesscorrected=(0 1) gop5=0 dem5=0 conservative2=4 male=1 white=1 education=3 age=53) vsquish
marginsplot, x(sciencespendguess)  recast(line) title("") yti("Pr(support increased science spending)") legend(order(1 "Control" 2 "Treatment") ring(0) pos(8) cols(1)) scheme(s1mono) recastci(rarea) ci1opts(fintensity(20)) level(95) xtitle(Science spending estimate)

* Supporting Information *

* SI Table 1
sum white male gop5 dem5 
sum age, detail
tab ideo5
tab educ
tab religpew

* SI Table 2: Multinomial Logits *
mlogit sciencespendpref3 guesscorrected gop5 dem5 conservative2 education white male age, base(2)
outreg2 using sitable2, word dec(2) label replace
mlogit sciencespendpref3 guesscorrected guesscorrectedxgop5 guesscorrectedxdem5 gop5 dem5 conservative2 education white male age, base(2)
outreg2 using sitable2, word dec(2) label append
mlogit sciencespendpref3 guesscorrected guesscorrectedxconservative2 gop5 dem5 conservative2 education white male age, base(2) 
outreg2 using sitable2, word dec(2) label append
mlogit sciencespendpref3 guesscorrected guesscorrectedxsciencespendguess gop5 dem5 conservative2 education white male age sciencespendguess, base(2)
outreg2 using sitable2, word dec(2) label append

* SI Figure 1: Simple Difference in Means Analysis *
gen means = .
gen sds = .
gen sqrtn = .
gen ses = .
gen counter = _n
label define diffs 1 "Control" 2 "Corrected" 3 "GOP X Control" 4 "GOP X Corrected" 5 "Dem X Control" 6 "Dem X Corrected"
label values counter diffs

sum increasess if guesscorrected == 0
replace means = r(mean) if counter == 1
replace sds = r(sd) if counter == 1
replace sqrtn = r(N) if counter == 1
replace sqrtn = sqrt(sqrtn) if counter == 1
replace ses = sds/sqrtn if counter == 1

sum increasess if guesscorrected == 1
replace means = r(mean) if counter == 2
replace sds = r(sd) if counter == 2
replace sqrtn = r(N) if counter == 2
replace sqrtn = sqrt(sqrtn) if counter == 2
replace ses = sds/sqrtn if counter == 2

sum increasess if guesscorrected == 0 & gop5 == 1
replace means = r(mean) if counter == 3
replace sds = r(sd) if counter == 3
replace sqrtn = r(N) if counter == 3
replace sqrtn = sqrt(sqrtn) if counter == 3
replace ses = sds/sqrtn if counter == 3

sum increasess if guesscorrected == 1 & gop5 == 1
replace means = r(mean) if counter == 4
replace sds = r(sd) if counter == 4
replace sqrtn = r(N) if counter == 4
replace sqrtn = sqrt(sqrtn) if counter == 4
replace ses = sds/sqrtn if counter == 4

sum increasess if guesscorrected == 0 & dem5 == 1
replace means = r(mean) if counter == 5
replace sds = r(sd) if counter == 5
replace sqrtn = r(N) if counter == 5
replace sqrtn = sqrt(sqrtn) if counter == 5
replace ses = sds/sqrtn if counter == 5

sum increasess if guesscorrected == 1 & dem5 == 1
replace means = r(mean) if counter == 6
replace sds = r(sd) if counter == 6
replace sqrtn = r(N) if counter == 6
replace sqrtn = sqrt(sqrtn) if counter == 6
replace ses = sds/sqrtn if counter == 6

serrbar means ses counter if counter < 8, scale (1.96) xlabel(, valuelabel angle(vertical)) ylabel(0 .2 .4 .6 .8 1) ytitle("Proportion Supporting Increased Spending" " ") xtitle("") xlabel(.5 " " 1 2 3 4 5 6 6.5 " ") graphregion(fcolor(white)) blcolor(black) mvopts(mcolor(black)) msymbol(circle)




